﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Collections;
using TS_XY_Train_Repaire.UserCon.SysSetting;
using TS_XY_Train_Repaire.UserCon.Main_Base;
using System.IO;

namespace TS_XY_Train_Repaire.SysSetting
{
    public partial class DocMana_jishu_ManaFrom : DevExpress.XtraEditors.XtraForm
    {
        public DocMana_jishu_ManaFrom()
        {
            InitializeComponent();
        }
        static string strdepid;// = string.Empty;
        static string mainid;//主表id
        private void Sys_Settings_Tree_Level_Main_ManaFrom_Load(object sender, EventArgs e)
        {
            strdepid=TS_Win_Class.GetSQlFieldValue_1("select * from TS_S_T_P_Tree where f_type=0 and f_del=0 and f_str_0="+TS_Win_Locomotive_MainForm.pUserInfoMain.UserDepTopID, "f_id");
            mainid = TS_Win_Class.GetSQlFieldValue_1("select * from TS_S_T_P_Tree_Main where  f_del=0 and f_str_0=" + TS_Win_Locomotive_MainForm.pUserInfoMain.UserDepTopID, "f_id");
            _LoadTreeList();
        }

        private void Sys_Settings_Tree_Level_Main_ManaFrom_FormClosing(object sender, FormClosingEventArgs e)
        {
            TS_Win_Locomotive_MainForm.htActionItem.Remove(this.Name);
        }
        #region//--系统目录事件--//
        private void _LoadTreeList()
        {
            //tl_Level.Nodes.Clear();
            DataTable _dt = new DataTable();
            tl_Tree.Nodes.Clear();
            tl_Tree.Refresh();
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            ArrayList pList = new ArrayList();
            //_ls = new LeverString_SysTreeMainList();
            //_ls.f_id = "M-1";
            //_ls.f_name = "系统底层数据目录";
            //_ls.f_imgindex = 4;
            //pList.Add(_ls);
            try
            {
                string strSQL = "select * from TS_S_T_P_Tree where f_id=" + strdepid + " and f_type=0";
                //string strSQL = "select f_str_0 as f_string,* from TS_S_T_P_Tree where f_mainid=5 and f_type=1 and (f_id in (select f_menuid from TS_S_T_S_Tree_Authority where ((f_funcid=3 and f_type=0) or (f_funcid=5 and f_type=1) or ((f_funcid=14 or f_funcid in (select f_id from TS_S_T_P_Department where f_del=0 and f_level like '%,14,%')) and f_type=2)) and f_del=0) or f_func_0=0) and f_del=0";
                SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
                conn.Open();
                SqlCommand cmd = new SqlCommand(strSQL, conn);
                SqlDataReader read = cmd.ExecuteReader();
                string _strUPID = "and (";
                int i = 0;
                while (read.Read())
                {
                    _ls = new LeverString_SysTreeMainList();
                    _ls.f_id = "T" + read["f_id"].ToString();
                    _ls.f_name = read["f_name"].ToString();
                    _ls.f_parent = "M-1";
                    _ls.f_deep = read["f_deep"].ToString();
                    _ls.f_level = read["f_level"].ToString();
                    _ls.f_type = read["f_type"].ToString();
                    _ls.f_str_0 = read["f_str_0"].ToString();
                    _ls.f_str_1 = read["f_str_1"].ToString();
                    _ls.f_str_2 = read["f_str_2"].ToString();
                    _ls.f_func_0 = read["f_func_0"].ToString();
                    _ls.f_func_1 = read["f_func_1"].ToString();
                    _ls.f_func_2 = read["f_func_2"].ToString();
                    if (read["f_type"].ToString() == "0")
                    {
                        _ls.f_imgindex = 5;
                    }
                    else
                    {
                        _ls.f_imgindex = 6;
                    }
                    if (i == 0)
                    {
                        _strUPID += "(f_level like '%," + read["f_id"].ToString() + ",%')";
                    }
                    else
                    {
                        _strUPID += "or (f_level like '%," + read["f_id"].ToString() + ",%')";
                    }
                    pList.Add(_ls);
                    i++;
                }
                _strUPID += ")";
                if (_strUPID.Length > 7)
                {
                    read.Close();
                    strSQL = "select * from TS_S_T_P_Tree where  (f_id in (select f_menuid from TS_S_T_S_Tree_Authority where ((f_funcid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_type=0) or (f_funcid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.UserPosID + " and f_type=1) or ((f_funcid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.UserDepIndex + " or f_funcid in (select f_id from TS_S_T_P_Department where f_del=0 and f_level like '%," + TS_Win_Locomotive_MainForm.pUserInfoMain.UserDepIndex + ",%')) and f_type=2)) and f_del=0) or f_func_0=0)   " + _strUPID + " and f_del=0 order by f_deep asc";
                    //MessageBox.Show(strSQL);
                    cmd = new SqlCommand(strSQL, conn);
                    read = cmd.ExecuteReader();
                    string _UPID = "";
                    while (read.Read())
                    {
                        _ls = new LeverString_SysTreeMainList();
                        _ls.f_id = "T" + read["f_id"].ToString();
                        _ls.f_name = read["f_name"].ToString();
                        _ls.f_deep = read["f_deep"].ToString();
                        _ls.f_level = read["f_level"].ToString();
                        _ls.f_type = read["f_type"].ToString();
                        _ls.f_str_0 = read["f_str_0"].ToString();
                        _ls.f_str_1 = read["f_str_1"].ToString();
                        _ls.f_str_2 = read["f_str_2"].ToString();
                        _ls.f_func_0 = read["f_func_0"].ToString();
                        _ls.f_func_1 = read["f_func_1"].ToString();
                        _ls.f_func_2 = read["f_func_2"].ToString();
                        _UPID = read["f_level"].ToString();
                        _UPID = _UPID.Substring(0, _UPID.Length - 1);
                        _UPID = _UPID.Substring(_UPID.LastIndexOf(',') + 1);
                        _ls.f_parent = "T" + _UPID;
                        if (read["f_type"].ToString() == "0")
                        {
                            _ls.f_imgindex = 5;
                        }
                        else
                        {
                            _ls.f_imgindex = 6;
                        }
                        pList.Add(_ls);
                    }
                }
                read.Close();
                conn.Close();
                conn.Dispose();
            }
            catch
            {
            }
            tl_Tree.DataSource = pList;
        }
        private void bbi_Tree_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = mainid;
            _ls.f_name = "文档资料";
            _ls.f_deep = "1";
            _ls.f_level = ",6,";
            _ls.f_type = "1";
            _ls.f_str_0 = "-";
            _ls.f_str_1 = "-";
            _ls.f_str_2 = "-";
            _ls.f_func_0 = "数据开放类型,公共功能,授权功能";
            _ls.f_func_1 = ",";
            _ls.f_func_2 = ",";
            uc_Main_Base_DocLevel_Mana _uc = new uc_Main_Base_DocLevel_Mana();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            try
            {
                _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
                _ls.f_mainid = tl_Tree.FocusedNode["f_mainid"].ToString();
                _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
                _ls.f_code = tl_Tree.FocusedNode["f_code"].ToString();
                _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
                _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
                _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
                _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
                _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
                _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
                _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
                _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
                _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            }
            catch
            {
            }
            _uc._ll = _ls;
            _uc._LoadType = "Sub_Add";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                //_LoadLevelList();
                //tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _uc._ll.f_id));
            }
            else
            {
            }
        }

        private void bbi_Tree_Edit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = mainid;
            _ls.f_name = "文档管理";
            _ls.f_deep = "1";
            _ls.f_level = ",6,";
            _ls.f_type = "1";
            _ls.f_str_0 = "-";
            _ls.f_str_1 = "-";
            _ls.f_str_2 = "-";
            _ls.f_func_0 = "数据开放类型,公共功能,授权功能";
            _ls.f_func_1 = ",";
            _ls.f_func_2 = ",";
            uc_Main_Base_DocLevel_Mana _uc = new uc_Main_Base_DocLevel_Mana();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            try
            {
                _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
                _ls.f_mainid = tl_Tree.FocusedNode["f_mainid"].ToString();
                _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
                _ls.f_code = tl_Tree.FocusedNode["f_code"].ToString();
                _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
                _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
                _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
                _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
                _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
                _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
                _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
                _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
                _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            }
            catch
            {
            }
            _uc._ll = _ls;
            _uc._LoadType = "Edit";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                //_LoadLevelList();
                //tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _uc._ll.f_id));
            }
            else
            {
            }
        }

        private void bbi_Tree_Del_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string _UpID = "-1";
            try
            {
                _UpID = tl_Tree.FocusedNode.ParentNode["f_id"].ToString();
            }
            catch
            { }
            LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
            _ls.f_id = mainid;
            _ls.f_name = "文档管理";
            _ls.f_deep = "1";
            _ls.f_level = ",6,";
            _ls.f_type = "1";
            _ls.f_str_0 = "-";
            _ls.f_str_1 = "-";
            _ls.f_str_2 = "-";
            _ls.f_func_0 = "数据开放类型,公共功能,授权功能";
            _ls.f_func_1 = ",";
            _ls.f_func_2 = ",";
            uc_Main_Base_DocLevel_Mana _uc = new uc_Main_Base_DocLevel_Mana();
            _uc._tl = _ls;
            _ls = new LeverString_SysTreeMainList();
            try
            {
                _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
                _ls.f_mainid = tl_Tree.FocusedNode["f_mainid"].ToString();
                _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
                _ls.f_code = tl_Tree.FocusedNode["f_code"].ToString();
                _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
                _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
                _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
                _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
                _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
                _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
                _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
                _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
                _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
            }
            catch
            {
            }
            _uc._ll = _ls;
            _uc._LoadType = "Del";
            if (_uc.ShowDialog() == DialogResult.OK)
            {
                _LoadTreeList();
                //tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _UpID));
            }
            else
            {
            }
        }

        private void tl_Tree_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            bbi_Tree_Add.Enabled = false;
            bbi_Tree_Edit.Enabled = false;
            bbi_Tree_Del.Enabled = false;
            //bbi_Level_Add.Enabled = false;
            //bbi_Level_Sub_Add.Enabled = false;
            //bbi_Level_Edit.Enabled = false;
            //bbi_Level_Del.Enabled = false;
            bbi_Level_Auth.Enabled = false;
            UpDoc.Enabled = false;
            try
            {
                //if (tl_Tree.FocusedNode["f_type"].ToString() == "1") { bbi_Level_Auth.Enabled = true; }

                if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "M")
                {
                    bbi_Tree_Add.Enabled = true;
                    //bbi_Level_Auth.Enabled = true;
                }
                else if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "T")
                {
                    bbi_Level_Auth.Enabled = true;
                    bbi_Tree_Add.Enabled = true;
                    bbi_Tree_Edit.Enabled = true;
                    UpDoc.Enabled = true;
                    bbi_Tree_Del.Enabled = true;
                    if (!Directory.Exists(TS_Win_Class._EXP_Direct))
                    {

                        Directory.CreateDirectory(TS_Win_Class._EXP_Direct);

                    }
                    if (File.Exists(TS_Win_Class._EXP_Direct + "Temp.pdf"))
                    {
                        File.Delete(TS_Win_Class._EXP_Direct + "Temp.pdf");
                    }
                    System.Data.DataTable dt = TS_Win_Class.GetFilledDataTable("select top 1 * from TS_S_T_P_Tree_Resource where f_del=0 and f_mainid= " + tl_Tree.FocusedNode["f_id"].ToString().Substring(1));
                    string file = dt.Rows[0]["f_brief"].ToString();
                    byte[] byteTo = Convert.FromBase64String(file);
                    string mTransRtf = System.Text.Encoding.Default.GetString(byteTo);
                    string fileName = "";
                    fileName = TS_Win_Class._EXP_Direct + "Temp.pdf";
                    System.IO.MemoryStream stream = new System.IO.MemoryStream(byteTo);
                    FileStream fs = new FileStream(fileName, FileMode.CreateNew);
                    BinaryWriter bw = new BinaryWriter(fs);

                    bw.Write(byteTo, 0, byteTo.Length);
                    bw.Close();
                    fs.Close();

                    PDF_Main.LoadFile(TS_Win_Class._EXP_Direct + "Temp.pdf");
                    if (tl_Tree.FocusedNode["f_type"].ToString() == "1")
                    {
                        //bbi_Level_Add.Enabled = true;
                    }
                }
            }
            catch
            {
            }
        }

        private void bbi_Reload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _LoadTreeList();
        }

        private void UpDoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            

            try
            {
                uc_Main_Base_UploadWord Upload = new uc_Main_Base_UploadWord();
                Upload.strLoadID = tl_Tree.FocusedNode["f_id"].ToString().Substring(1);
                if (Upload.ShowDialog() == DialogResult.OK)
                {
                    
                }
            }
            catch
            {
                PDF_Main.LoadFile(null);
            }
        }

        private void bbi_Level_Auth_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            uc_Sys_Settings_Level_Auth_ManaForm _uc = new uc_Sys_Settings_Level_Auth_ManaForm();
            _uc._LoadID = tl_Tree.FocusedNode["f_id"].ToString();
            _uc._LoadName = tl_Tree.FocusedNode["f_name"].ToString();
            _uc.ShowDialog();
        }

        //private void tl_Tree_DoubleClick(object sender, EventArgs e)
        //{
        //    f_func_0.Visible = false;
        //    f_func_1.Visible = false;
        //    f_func_2.Visible = false;
        //    f_str_0.Visible = false;
        //    f_str_1.Visible = false;
        //    f_str_2.Visible = false;
        //    if (tl_Tree.FocusedNode["f_type"].ToString() == "1")
        //    {
        //        if (tl_Tree.FocusedNode["f_str_0"].ToString() != "-")
        //        {
        //            f_str_0.Visible = true;
        //            f_str_0.Caption = tl_Tree.FocusedNode["f_str_0"].ToString();
        //        }
        //        if (tl_Tree.FocusedNode["f_str_1"].ToString() != "-")
        //        {
        //            f_str_1.Visible = true;
        //            f_str_1.Caption = tl_Tree.FocusedNode["f_str_1"].ToString();
        //        }
        //        if (tl_Tree.FocusedNode["f_str_2"].ToString() != "-")
        //        {
        //            f_str_2.Visible = true;
        //            f_str_2.Caption = tl_Tree.FocusedNode["f_str_2"].ToString();
        //        }
        //        if (tl_Tree.FocusedNode["f_func_0"].ToString() != ",")
        //        {
        //            f_func_0.Visible = true;
        //            f_func_0.Caption = tl_Tree.FocusedNode["f_func_0"].ToString().Split(',')[0];
        //        }
        //        if (tl_Tree.FocusedNode["f_func_1"].ToString() != ",")
        //        {
        //            f_func_1.Visible = true;
        //            f_func_1.Caption = tl_Tree.FocusedNode["f_func_1"].ToString().Split(',')[0];
        //        }
        //        if (tl_Tree.FocusedNode["f_func_2"].ToString() != ",")
        //        {
        //            f_func_2.Visible = true;
        //            f_func_2.Caption = tl_Tree.FocusedNode["f_func_2"].ToString().Split(',')[0];
        //        }
        //    }
        //    _LoadLevelList();
        //}
        #endregion
        #region//--目录数据事件--//
        //private void _LoadLevelList()
        //{
        //    //tl_Level.Nodes.Clear();
        //    LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
        //    ArrayList pList = new ArrayList();
        //    try
        //    {
        //        if (tl_Tree.FocusedNode["f_id"].ToString().Substring(0, 1) == "T" && tl_Tree.FocusedNode["f_type"].ToString() == "1")
        //        {
        //            string strSQL = "select * from TS_S_T_P_Tree where f_mainid=" + tl_Tree.FocusedNode["f_id"].ToString().Substring(1) + " and f_deep=0 and f_del=0";
        //            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
        //            conn.Open();
        //            SqlCommand cmd = new SqlCommand(strSQL, conn);
        //            SqlDataReader read = cmd.ExecuteReader();
        //            string _strUPID = "and (";
        //            int i = 0;
        //            while (read.Read())
        //            {
        //                _ls = new LeverString_SysTreeMainList();
        //                _ls.f_id = "L" + read["f_id"].ToString();
        //                _ls.f_name = read["f_name"].ToString();
        //                _ls.f_parent = "L-1";
        //                _ls.f_code = read["f_code"].ToString();
        //                _ls.f_mainid = read["f_mainid"].ToString();
        //                _ls.f_deep = read["f_deep"].ToString();
        //                _ls.f_level = read["f_level"].ToString();
        //                _ls.f_type = read["f_type"].ToString();
        //                _ls.f_str_0 = read["f_str_0"].ToString();
        //                _ls.f_str_1 = read["f_str_1"].ToString();
        //                _ls.f_str_2 = read["f_str_2"].ToString();
        //                _ls.f_func_0 = read["f_func_0"].ToString();
        //                _ls.f_func_1 = read["f_func_1"].ToString();
        //                _ls.f_func_2 = read["f_func_2"].ToString();
        //                if (read["f_type"].ToString() == "0")
        //                {
        //                    _ls.f_imgindex = 5;
        //                }
        //                else
        //                {
        //                    _ls.f_imgindex = 6;
        //                }
        //                if (i == 0)
        //                {
        //                    _strUPID += "(f_level like '%," + read["f_id"].ToString() + ",%')";
        //                }
        //                else
        //                {
        //                    _strUPID += "or (f_level like '%," + read["f_id"].ToString() + ",%')";
        //                }
        //                pList.Add(_ls);
        //                i++;
        //            }
        //            _strUPID += ")";
        //            if (_strUPID.Length > 7)
        //            {
        //                read.Close();
        //                strSQL = "select * from TS_S_T_P_Tree where f_mainid=" + tl_Tree.FocusedNode["f_id"].ToString().Substring(1) + " and f_deep>0 and f_del=0 " + _strUPID + " order by f_deep,f_level,f_name asc";
        //                cmd = new SqlCommand(strSQL, conn);
        //                read = cmd.ExecuteReader();
        //                string _UPID = "";
        //                while (read.Read())
        //                {
        //                    _ls = new LeverString_SysTreeMainList();
        //                    _ls.f_id = "L" + read["f_id"].ToString();
        //                    _ls.f_name = read["f_name"].ToString();
        //                    _ls.f_code = read["f_code"].ToString();
        //                    _ls.f_mainid = read["f_mainid"].ToString();
        //                    _ls.f_deep = read["f_deep"].ToString();
        //                    _ls.f_level = read["f_level"].ToString();
        //                    _ls.f_type = read["f_type"].ToString();
        //                    _ls.f_str_0 = read["f_str_0"].ToString();
        //                    _ls.f_str_1 = read["f_str_1"].ToString();
        //                    _ls.f_str_2 = read["f_str_2"].ToString();
        //                    _ls.f_func_0 = read["f_func_0"].ToString();
        //                    _ls.f_func_1 = read["f_func_1"].ToString();
        //                    _ls.f_func_2 = read["f_func_2"].ToString();
        //                    _UPID = read["f_level"].ToString();
        //                    _UPID = _UPID.Substring(0, _UPID.Length - 1);
        //                    _UPID = _UPID.Substring(_UPID.LastIndexOf(',') + 1);
        //                    _ls.f_parent = "L" + _UPID;
        //                    if (read["f_type"].ToString() == "0")
        //                    {
        //                        _ls.f_imgindex = 5;
        //                    }
        //                    else
        //                    {
        //                        _ls.f_imgindex = 6;
        //                    }
        //                    pList.Add(_ls);
        //                }
        //            }
        //            read.Close();
        //            conn.Close();
        //            conn.Dispose();
        //        }
        //    }
        //    catch
        //    {
        //    }
        //    //tl_Level.DataSource = pList;
        //}
        //private void bbi_Level_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{
        //    LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
        //    _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
        //    _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
        //    _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
        //    _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
        //    _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
        //    _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
        //    _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
        //    _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
        //    _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
        //    _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
        //    _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
        //    uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
        //    _uc._tl = _ls;
        //    _ls = new LeverString_SysTreeMainList();
        //    _ls.f_mainid = "Add";
        //    try
        //    {
        //        _ls.f_id = tl_Level.FocusedNode["f_id"].ToString();
        //        _ls.f_mainid = tl_Level.FocusedNode["f_mainid"].ToString();
        //        _ls.f_name = tl_Level.FocusedNode["f_name"].ToString();
        //        _ls.f_code = tl_Level.FocusedNode["f_code"].ToString();
        //        _ls.f_deep = tl_Level.FocusedNode["f_deep"].ToString();
        //        _ls.f_level = tl_Level.FocusedNode["f_level"].ToString();
        //        _ls.f_type = tl_Level.FocusedNode["f_type"].ToString();
        //        _ls.f_str_0 = tl_Level.FocusedNode["f_str_0"].ToString();
        //        _ls.f_str_1 = tl_Level.FocusedNode["f_str_1"].ToString();
        //        _ls.f_str_2 = tl_Level.FocusedNode["f_str_2"].ToString();
        //        _ls.f_func_0 = tl_Level.FocusedNode["f_func_0"].ToString();
        //        _ls.f_func_1 = tl_Level.FocusedNode["f_func_1"].ToString();
        //        _ls.f_func_2 = tl_Level.FocusedNode["f_func_2"].ToString();
        //    }
        //    catch
        //    {
        //    }
        //    _uc._ll = _ls;
        //    _uc._LoadType = "Add";
        //    if (_uc.ShowDialog() == DialogResult.OK)
        //    {
        //        _LoadLevelList();
        //        tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _uc._ll.f_id));
        //    }
        //    else
        //    {
        //    }
        //}
        //private void bbi_Level_Sub_Add_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{
        //    LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
        //    _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
        //    _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
        //    _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
        //    _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
        //    _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
        //    _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
        //    _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
        //    _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
        //    _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
        //    _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
        //    _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
        //    uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
        //    _uc._tl = _ls;
        //    _ls = new LeverString_SysTreeMainList();
        //    try
        //    {
        //        _ls.f_id = tl_Level.FocusedNode["f_id"].ToString();
        //        _ls.f_mainid = tl_Level.FocusedNode["f_mainid"].ToString();
        //        _ls.f_name = tl_Level.FocusedNode["f_name"].ToString();
        //        _ls.f_code = tl_Level.FocusedNode["f_code"].ToString();
        //        _ls.f_deep = tl_Level.FocusedNode["f_deep"].ToString();
        //        _ls.f_level = tl_Level.FocusedNode["f_level"].ToString();
        //        _ls.f_type = tl_Level.FocusedNode["f_type"].ToString();
        //        _ls.f_str_0 = tl_Level.FocusedNode["f_str_0"].ToString();
        //        _ls.f_str_1 = tl_Level.FocusedNode["f_str_1"].ToString();
        //        _ls.f_str_2 = tl_Level.FocusedNode["f_str_2"].ToString();
        //        _ls.f_func_0 = tl_Level.FocusedNode["f_func_0"].ToString();
        //        _ls.f_func_1 = tl_Level.FocusedNode["f_func_1"].ToString();
        //        _ls.f_func_2 = tl_Level.FocusedNode["f_func_2"].ToString();
        //    }
        //    catch
        //    {
        //    }
        //    _uc._ll = _ls;
        //    _uc._LoadType = "Sub_Add";
        //    if (_uc.ShowDialog() == DialogResult.OK)
        //    {
        //        _LoadLevelList();
        //        tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _uc._ll.f_id));
        //    }
        //    else
        //    {
        //    }
        //}
        //private void bbi_Level_Edit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{
        //    LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
        //    _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
        //    _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
        //    _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
        //    _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
        //    _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
        //    _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
        //    _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
        //    _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
        //    _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
        //    _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
        //    _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
        //    uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
        //    _uc._tl = _ls;
        //    _ls = new LeverString_SysTreeMainList();
        //    try
        //    {
        //        _ls.f_id = tl_Level.FocusedNode["f_id"].ToString();
        //        _ls.f_mainid = tl_Level.FocusedNode["f_mainid"].ToString();
        //        _ls.f_name = tl_Level.FocusedNode["f_name"].ToString();
        //        _ls.f_code = tl_Level.FocusedNode["f_code"].ToString();
        //        _ls.f_deep = tl_Level.FocusedNode["f_deep"].ToString();
        //        _ls.f_level = tl_Level.FocusedNode["f_level"].ToString();
        //        _ls.f_type = tl_Level.FocusedNode["f_type"].ToString();
        //        _ls.f_str_0 = tl_Level.FocusedNode["f_str_0"].ToString();
        //        _ls.f_str_1 = tl_Level.FocusedNode["f_str_1"].ToString();
        //        _ls.f_str_2 = tl_Level.FocusedNode["f_str_2"].ToString();
        //        _ls.f_func_0 = tl_Level.FocusedNode["f_func_0"].ToString();
        //        _ls.f_func_1 = tl_Level.FocusedNode["f_func_1"].ToString();
        //        _ls.f_func_2 = tl_Level.FocusedNode["f_func_2"].ToString();
        //    }
        //    catch
        //    {
        //    }
        //    _uc._ll = _ls;
        //    _uc._LoadType = "Edit";
        //    if (_uc.ShowDialog() == DialogResult.OK)
        //    {
        //        _LoadLevelList();
        //        tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _uc._ll.f_id));
        //    }
        //    else
        //    {
        //    }
        //}

        //private void bbi_Level_Del_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{
        //    string _UpID = "-1";
        //    try
        //    {
        //        _UpID = tl_Level.FocusedNode.ParentNode["f_id"].ToString();
        //    }
        //    catch
        //    { }
        //    LeverString_SysTreeMainList _ls = new LeverString_SysTreeMainList();
        //    _ls.f_id = tl_Tree.FocusedNode["f_id"].ToString();
        //    _ls.f_name = tl_Tree.FocusedNode["f_name"].ToString();
        //    _ls.f_deep = tl_Tree.FocusedNode["f_deep"].ToString();
        //    _ls.f_level = tl_Tree.FocusedNode["f_level"].ToString();
        //    _ls.f_type = tl_Tree.FocusedNode["f_type"].ToString();
        //    _ls.f_str_0 = tl_Tree.FocusedNode["f_str_0"].ToString();
        //    _ls.f_str_1 = tl_Tree.FocusedNode["f_str_1"].ToString();
        //    _ls.f_str_2 = tl_Tree.FocusedNode["f_str_2"].ToString();
        //    _ls.f_func_0 = tl_Tree.FocusedNode["f_func_0"].ToString();
        //    _ls.f_func_1 = tl_Tree.FocusedNode["f_func_1"].ToString();
        //    _ls.f_func_2 = tl_Tree.FocusedNode["f_func_2"].ToString();
        //    uc_Sys_Settings_Level_ManaForm _uc = new uc_Sys_Settings_Level_ManaForm();
        //    _uc._tl = _ls;
        //    _ls = new LeverString_SysTreeMainList();
        //    try
        //    {
        //        _ls.f_id = tl_Level.FocusedNode["f_id"].ToString();
        //        _ls.f_mainid = tl_Level.FocusedNode["f_mainid"].ToString();
        //        _ls.f_name = tl_Level.FocusedNode["f_name"].ToString();
        //        _ls.f_code = tl_Level.FocusedNode["f_code"].ToString();
        //        _ls.f_deep = tl_Level.FocusedNode["f_deep"].ToString();
        //        _ls.f_level = tl_Level.FocusedNode["f_level"].ToString();
        //        _ls.f_type = tl_Level.FocusedNode["f_type"].ToString();
        //        _ls.f_str_0 = tl_Level.FocusedNode["f_str_0"].ToString();
        //        _ls.f_str_1 = tl_Level.FocusedNode["f_str_1"].ToString();
        //        _ls.f_str_2 = tl_Level.FocusedNode["f_str_2"].ToString();
        //        _ls.f_func_0 = tl_Level.FocusedNode["f_func_0"].ToString();
        //        _ls.f_func_1 = tl_Level.FocusedNode["f_func_1"].ToString();
        //        _ls.f_func_2 = tl_Level.FocusedNode["f_func_2"].ToString();
        //    }
        //    catch
        //    {
        //    }
        //    _uc._ll = _ls;
        //    _uc._LoadType = "Del";
        //    if (_uc.ShowDialog() == DialogResult.OK)
        //    {
        //        _LoadLevelList();
        //        tl_Level.SetFocusedNode(tl_Level.FindNodeByFieldValue("f_id", _UpID));
        //    }
        //    else
        //    {
        //    }
        //}

        //private void tl_Level_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        //{
        //    bbi_Level_Sub_Add.Enabled = false;
        //    bbi_Level_Edit.Enabled = false;
        //    bbi_Level_Del.Enabled = false;
        //    bbi_Level_Auth.Enabled = false;
        //    bbi_Level_Rel.Enabled = false;
        //    try
        //    {
        //        if (tl_Level.FocusedNode["f_id"].ToString().Substring(0, 1) == "L")
        //        {
        //            bbi_Level_Sub_Add.Enabled = true;
        //            bbi_Level_Edit.Enabled = true;
        //            bbi_Level_Del.Enabled = true;
        //            if (tl_Level.FocusedNode["f_type"].ToString() == "1")
        //            {
        //                bbi_Level_Auth.Enabled = true;
        //                bbi_Level_Rel.Enabled = true;
        //            }
        //        }
        //    }
        //    catch
        //    {
        //    }
        }

        //private void tl_Level_DoubleClick(object sender, EventArgs e)
        //{

        //}

        //private void bbi_Level_Auth_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{

        //}

        //private void bbi_Level_Rel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //{

        //}

        #endregion
//        private void bbi_Reload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
//        {
//            string _UpID = "0";
//            try
//            {
//                _UpID = tl_Tree.FocusedNode["f_id"].ToString();
//            }
//            catch
//            {
//            }
//            _LoadTreeList();
//            try
//            {
//                tl_Tree.SetFocusedNode(tl_Tree.FindNodeByFieldValue("f_id", _UpID));
//            }
//            catch
//            {
//            }
//}
    }